<template>
  <a-modal :okText="`申请加入`" destroyOnClose :title="$t(title)" type="info" :cancelText="$t('common.cancel')" :visible="visible" :width="720" @cancel="cancelModal(false)" @ok="cancelModal(true)" class="JoinCompany">
    <a-form :form="form" labelAlign="left">
        <a-row :gutter="24">
          <a-col :span="24">
            <a-form-item label="请准确输入希望加入的猎头企业管理员邮箱" v-bind="formItemLayout">
              <a-input v-decorator="['manager',{rules: [{ required: true, message: `请输入邮箱` }]}]" placeholder="邮箱" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="请准确输入希望加入的猎头企业名称" v-bind="formItemLayout">
              <a-input v-decorator="['expectationOfHeadhunters',{rules: [{ required: true, message: `请输入企业名称` }]}]" placeholder="企业名称" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <p class="error_text">*管理员通过后操作不可撤销，当前公司的职位和简历数据将合并到加入的猎头企业！！！</p>
  </a-modal>
</template>

<script>
import { mapState } from 'vuex'
import { twoArrCludes } from '@/util/roles'
import { accountMerge } from '@/api/employingUnit'
export default {
  name: 'JoinCompany',
  props: ['visible', 'combine'],
  data () {
    return {
      form: this.$form.createForm(this),
      formItemLayout: {
        labelCol: { span: 12 },
        wrapperCol: { span: 12 }
      },
      title: '加入猎头企业'
    }
  },
  computed: {
    ...mapState({
      userInfo: state => state.user.userInfo
    })
  },
  watch: {
    visible: {
      handler (newValue, oldValue) {
        if (newValue) {
          this.initData()
        }
      },
      immediate: true
    }
  },
  methods: {
    twoArrCludes,
    initData () {
    },
    cancelModal (flag) {
      // 提交数据
      if (flag) {
        this.arrangeData()
      } else {
        this.$emit('close')
      }
    },
    async mergeData (values) {
      let params = {
        expectationOfHeadhunters: values.expectationOfHeadhunters,
        manager: values.manager,
        id: this.combine.id
      }
      let res = await accountMerge(params)
      if (res.code === 200) {
        this.$message.success(res.message)
        this.$emit('close', true)
      } else {
        this.$message.error(res.message)
      }
    },
    arrangeData () {
      this.form.validateFields((err, values) => {
        if (!err) {
          this.mergeData(values)
        }
      })
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '../../styles/var.styl'
</style>
